function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

var offsetxpoint	=	-20;	// 
var offsetypoint	=	20;		// 
var ie	=	document.all;
var ns6	=	document.getElementById && !document.all;
var safari	=	isSafari();
var enabletip	=	false;
var objname = "";

//显示提示
function showTip(idname,messageContent){
	
	objname=idname;
	var tipObject = MM_findObj(objname);
	tipObject.innerHTML = messageContent;
	enabletip = true;
	return false;
}

//隐藏提示
function hideTip(idname){
	
	var tipObject = MM_findObj(objname);	
	enabletip = false;
	tipObject.style.visibility = "hidden";
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
function isSafari(){
	return navigator.userAgent.toLowerCase().indexOf("safari") + 1;
}

function positionTip(e)
{
	if (enabletip)
	{
		var tipobj = MM_findObj(objname);
		
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20;
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20;
		
		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000
		
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
		{
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
		}
		else if (curX<leftedge)
		{
			tipobj.style.left="5px"
		}
		else
		{
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetxpoint+"px";
		}

		if(safari)
		{
			tipobj.style.top=curY+offsetypoint+"px";
		}
		else
		{
			//same concept with the vertical position
			if (bottomedge<tipobj.offsetHeight)
			{
				tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px";
			}
			else
			{
				tipobj.style.top=curY+offsetypoint+"px";
			}
		}
		tipobj.style.visibility="visible";
	}
}

document.onmousemove = positionTip;